#ifndef __BSP_CAN_H
#define __BSP_CAN_H
#include "main.h"
#include "can.h"
#include <string.h>

// 各个电机向总线反馈数据时的帧头
#define MOTOR_RX_ID_1				0x209
#define MOTOR_RX_ID_2				0x18
#define MOTOR_RX_ID_3				0x19
#define MOTOR_RX_ID_4				0x01
#define MOTOR_RX_ID_5				0x201
#define MOTOR_RX_ID_6				0x202

// 各个电机的地址
#define MOTOR_TX_ID_2       0x008
#define MOTOR_TX_ID_3       0x009

extern volatile uint8_t can_rx_data[6][8];
extern uint32_t can_callback_cnt;

void BSP_CAN_Init(void);
void CAN_Filter_Init(void);
uint8_t BSP_CAN_SendData(CAN_HandleTypeDef *hcan, uint16_t id, uint8_t *data, uint32_t len);
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan);
void BSP_CAN1_RX_Callback(CAN_HandleTypeDef *hcan);

extern uint8_t can_filter_init_error;
extern uint32_t can_errorcode;
extern HAL_CAN_StateTypeDef can_state;
extern uint8_t can_mode;
extern uint32_t can_instace_ier;
extern uint32_t can_instance_esr;
void BSP_CAN_CheckStatus(void);

extern volatile uint32_t debug_msr ;
extern volatile uint32_t debug_tsr ;
extern volatile uint32_t debug_rf0r;
extern volatile uint32_t debug_rf1r;
void BSP_CAN_GetDetailedStatus(void);
void BSP_CAN_Reset(void);

void can_filter_init(void);
uint8_t canx_send_data(CAN_HandleTypeDef *hcan, uint16_t id, uint8_t *data, uint32_t len);


void set_motor_voltage(uint8_t id_range, int16_t v1, int16_t v2, int16_t v3, int16_t v4);
#endif
